package com.jcfk.eam.controller.bd;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.base.EamTeamMemberDTO;
import com.jcfk.eam.domain.query.base.EamTeamMemberQuery;
import com.jcfk.eam.service.base.EamTeamMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.common.core.utils.ExcelUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 运维班组成员
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-08-14
 */
@Api(tags = {"运维班组成员管理"})
@RestController
@RequestMapping("eamteammember")
public class EamTeamMemberController {
    @Autowired
    private EamTeamMemberService eamTeamMemberService;

    /**
     * 分页列表
     */
    @ApiOperation("分页查询运维班组成员")
    @PostMapping("/queryByPage")
    public RetPage<EamTeamMemberDTO> queryByPage(@RequestBody ReqPageParam<EamTeamMemberQuery> requestParam) {
        DataPage<EamTeamMemberDTO> page = new DataPage<EamTeamMemberDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamTeamMemberDTO.class);
        page = eamTeamMemberService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  运维班组成员
     * 根据id 查询详情
     */
    @ApiOperation("查询运维班组成员")
    @GetMapping("/get/{id}")
    public RetResult<EamTeamMemberDTO> get(@PathVariable("id") String id) {
            EamTeamMemberDTO item = eamTeamMemberService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理运维班组成员
     */
    @ApiOperation("保存运维班组成员")
    @PostMapping("/save")
    @RequestLogHeader(modular = "运维班组成员管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamTeamMemberDTO eamTeamMember) {
        // 数据校验
        RetResult ret = eamTeamMemberService.isValid(eamTeamMember);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamTeamMember.getId())){
            // 新增
            eamTeamMemberService.insert(eamTeamMember);
        } else{
            // 更新
            eamTeamMemberService.update(eamTeamMember);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除运维班组成员
     */
    @ApiOperation("批量删除运维班组成员")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "运维班组成员管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamTeamMemberDTO eamTeamMember) {
        return RetResult.ok(eamTeamMemberService.logicDeleteList(eamTeamMember));
    }

    /**
     *  删除运维班组成员
     */
    @ApiOperation("删除运维班组成员")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "运维班组成员管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamTeamMemberService.deleteitem(id);
        return RetResult.ok();
    }

    @ApiOperation("获取成员列表")
    @PostMapping("/getList")
    public RetResult<?> getList(@RequestBody EamTeamMemberQuery query) {
        if(CollUtil.isEmpty(query.getTeamIdList()) && StrUtil.isEmpty(query.getTeamId())){
            return RetResult.ok(new ArrayList<>());
        }
        List<EamTeamMemberDTO> list=eamTeamMemberService.getList(query);
        return RetResult.ok(list);
    }
}
